package listdemo.demo01;

import java.util.ArrayList;
import java.util.List;

public class StudentListDemo {
    public static void main(String[] args) {
        //创建学生对象
        Student student = new Student("刘亦菲", 18);
        Student student2 = new Student("古天乐", 29);
        Student student3 = new Student("渣渣辉", 34);

        //创建集合对象
        List<Student> list = new ArrayList<>();

        //添加学生对象到集合
        list.add(student);
        list.add(student2);
        list.add(student3);

        //遍历
        //1 迭代器
        boolean b = list.iterator().hasNext();
        while (b) {
            Student next = list.iterator().next();

            System.out.println(next.getName() + " " + next.getAge());

        }

        //增强for循环
        for(Student s:list){
            System.out.println(s.getName()+" "+s.getAge());
        }
        //lambda
        list.forEach(s ->{
            System.out.println(s.getName()+" "+s.getAge());
        });
        //普通for
        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i).getName()+" "+list.get(i).getAge());
        }

    }
}
